#-*- coding: utf-8 -*-
'''
Created on Aug 27, 2012

@author: bbg
'''

from sqlalchemy import Integer, Column, String, MetaData, Table
from sqlalchemy.orm import mapper
    
class OrderPaymentMode(object):

    _Mapper_ = None
    _company_id_ = -1
    _shop_id_ = -1    
    def __init__(self):
        self.order_id = ''
        self.payment_name = ''
        self.amount = 0
        self.exchange_rate = 0
        self.original_cash_amount = 0
        self.create_time = ''
        self.modify_time = ''
        
    @staticmethod
    def doMapping(company_id, shop_id, year):
        '''
        按company_id分库，shop_id对应公司分店，每次生成对象前都要执行一次，以便map到正确的数据库上去
        '''
        if OrderPaymentMode._company_id_ == company_id and OrderPaymentMode._shop_id_ == shop_id:
            return
                
        if OrderPaymentMode._Mapper_ is not None:
            OrderPaymentMode._Mapper_.dispose()
            
        metaData = MetaData()
        tableName = 'order_payment_mode_%s' % year
        orderPaymentModeTable = Table(tableName, metaData,
                           Column('order_id', String, primary_key = True),
                           Column('payment_name', String, primary_key = True),
                           Column('amount', Integer),
                           Column('exchange_rate', Integer),
                           Column('original_cash_amount', Integer),
                           Column('create_time', String),
                           Column('modify_time', String),                           
                           schema = "shop_order_%s_%s" % (company_id, shop_id))
        
        OrderPaymentMode._Mapper_ = mapper(OrderPaymentMode, orderPaymentModeTable)
    